package com.xyz.springcloud.controller;

import com.xyz.springcloud.entity.CommonResult;
import com.xyz.springcloud.entity.Payment;
import com.xyz.springcloud.service.impl.PaymentServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 肖咉卓
 */
@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentServiceImpl paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/payment/add")
    public CommonResult create(@RequestBody Payment payment){
        int result =paymentService.addPayment(payment);
        log.info("****插入结果"+result);
        if(result>0){
            return new CommonResult<Integer>(200,"数据插入成功"+serverPort,result);
        }
        return new CommonResult(444,"数据插入失败",null);
    }
    @GetMapping("/payment/get/{id}")
    public CommonResult find(@PathVariable("id") Long id){
        Payment payment =paymentService.findPaymentId(id);
        log.info("****插入结果"+payment);
        if(payment != null){
            return new CommonResult<Payment>(200,"数据查询成功"+serverPort,payment);
        }
        return new CommonResult(444,"数据查询失败",null);
    }

    @GetMapping(value = "/payment/lb")
    public String getPaymentLB(){
        return serverPort;
    }

}
